home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / ClassicPane.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  10.1 KB  |  354 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ClassicPane.cp
  3.  
  4.     Contains:    Class to drive our classic pane, showing new versions of old favorites.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997, 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (jss)    Jeff Shulman
  21.         (MAA)    Matt Ackeret
  22.         (edv)    Ed Voas
  23.  
  24.     Change History (most recent first):
  25.  
  26.        <1.6>     4/19/99    jss        Added help from balloons
  27.     $Log: ClassicPane.cp,v $
  28.     Revision 1.7  1999/04/29 20:52:11  voas
  29.     use HELP_TAGS_ENABLED
  30.     
  31.     Revision 1.6  1999/04/19 21:21:19  kilroy
  32.     Added help from balloons
  33.     
  34.     Revision 1.5  1999/04/15 00:39:22  mattack
  35.     guyf edited the sources so they'd build on 8 and X while menu stuff was
  36.     in flux.
  37.     
  38.  
  39.        <1.4>      4/7/99    jss        Fix CarbonLib compilation problems
  40.          <3>    11/17/97    MAA        fix error wrt. pagedown in the vertical scrollbar
  41.          <2>    10/28/97    edv        Use Radio Group control!
  42.          <1>     9/11/97    edv        First checked in.
  43. */
  44.  
  45. #include "AppearanceSamplePrefix.h"
  46.  
  47. #include <Appearance.h>
  48. #include <MacHelp.h>
  49. #include "ClassicPane.h"
  50. #include "AppearanceHelpers.h"
  51. #include "UDialogUtils.h"
  52.  
  53. #define MIN( a, b )        ( ( (a) < (b) ) ? (a) : (b) )
  54. #define MAX( a, b )        ( ( (a) > (b) ) ? (a) : (b) )
  55.  
  56. enum
  57. {
  58.     kEngageButton             = 1,
  59.     kMakeItSoButton            = 2,
  60.     kEjectCoreButton        = 3,
  61.     kRaiseShieldsButton        = 4,
  62.     kUserItem                = 6,
  63.     kVerticalScrollBar        = 7,
  64.     kHorizontalScrollBar    = 8,
  65.     kTuneUpCheckBox         = 9,
  66.     kConstrictorsCheckBox    = 10,
  67.     kIntermixCheckBox        = 11,
  68.     kRadioGroup                = 12,
  69.     kDessertRadio            = 13,
  70.     kFloorWaxRadio            = 14,
  71.     kBothButton                = 15
  72. };
  73.  
  74. enum
  75. {
  76.     kConstrictorsMask        = 1,
  77.     kIntermixMask            = 2,
  78.     kAllCheckMask            = 3
  79. };
  80.  
  81. ControlActionUPP    ClassicPane::fScrollBarProc = NewControlActionProc( ClassicPane::ScrollingFeedbackProc );
  82. ControlUserPaneDrawUPP    ClassicPane::fDrawProc = NewControlUserPaneDrawProc( ClassicPane::DrawPictureProc );
  83.  
  84. ClassicPane::ClassicPane( DialogPtr dialog, SInt16 items ) : MegaPane( dialog, items )
  85. {
  86.     ControlHandle        control;
  87.     Rect                bounds;
  88.  
  89.     AppendDialogItemList( dialog, 6003, overlayDITL );
  90.  
  91.     GetDialogItemAsControl( dialog, kTuneUpCheckBox + items, &control );
  92.     SetControlMaximum( control, 2 );
  93.  
  94.     GetDialogItemAsControl( dialog, kMakeItSoButton + items, &control );
  95.     SetPushButtonDefaultState( control, true );
  96.     
  97.     GetDialogItemAsControl( dialog, kEjectCoreButton + items, &control );
  98.     DeactivateControl( control );
  99.  
  100.     GetDialogItemAsControl( dialog, items + kHorizontalScrollBar, &fHorizontalScrollBar );
  101.     GetDialogItemAsControl( dialog, items + kVerticalScrollBar, &fVerticalScrollBar );
  102.     
  103.     SetControlReference( fHorizontalScrollBar, (long)this );
  104.     SetControlReference( fVerticalScrollBar, (long)this );
  105.     
  106.     fPictOffset.h = 0;
  107.     fPictOffset.v = 0;
  108.     
  109.     fPicture = GetPicture( 6003 );
  110.     fPictWidth = (**fPicture).picFrame.right - (**fPicture).picFrame.left;
  111.     fPictHeight = (**fPicture).picFrame.bottom - (**fPicture).picFrame.top;
  112.     
  113.     GetDialogItemAsControl( dialog, items + kUserItem, &fUserItem );
  114.     SetControlReference( fUserItem, (long)this );
  115.     SetControlData( fUserItem, 0, kControlUserPaneDrawProcTag, sizeof( fDrawProc ), (Ptr)&fDrawProc );
  116.  
  117.     GetControlBounds( fUserItem, &bounds );
  118.     fUserItemHeight = bounds.bottom - bounds.top;
  119.     fUserItemWidth = bounds.right - bounds.left;
  120.     
  121.     SetControlMaximum( fHorizontalScrollBar, fPictWidth - fUserItemWidth );
  122.     SetControlMaximum( fVerticalScrollBar, fPictHeight - fUserItemHeight );
  123.     
  124.     SetControlAction( fHorizontalScrollBar, fScrollBarProc );
  125.     SetControlAction( fVerticalScrollBar, fScrollBarProc );
  126.     
  127.     GetDialogItemAsControl( dialog, fOrigItems + kDessertRadio, &control );
  128.     SetControlMaximum( control, kControlCheckBoxMixedValue );
  129.     GetDialogItemAsControl( dialog, fOrigItems + kFloorWaxRadio, &control );
  130.     SetControlMaximum( control, kControlCheckBoxMixedValue );
  131.  
  132. #if HELP_TAGS_ENABLED    
  133.     {
  134.         // Set help for the Engage button
  135.         HMHelpContentRec    controlHelpContent;
  136.         GrafPtr                currPort;
  137.         
  138.         GetDialogItemAsControl( dialog, kEngageButton + items, &control );
  139.  
  140.         controlHelpContent.version = kMacHelpVersion;
  141.         
  142.         ::GetControlBounds( control, &controlHelpContent.absHotRect );
  143.         
  144.         ::GetPort( &currPort );
  145.         ::SetPortDialogPort( dialog );
  146.         ::LocalToGlobal( &topLeft(controlHelpContent.absHotRect) );
  147.         ::LocalToGlobal( &botRight(controlHelpContent.absHotRect) );
  148.         ::MacSetPort( currPort );
  149.         
  150.         controlHelpContent.tagSide = kHMDefaultSide;
  151.  
  152.         // Our minimum content is on a STR# resource
  153.         controlHelpContent.content[ kHMMinimumContentIndex ].contentType = kHMStringResContent;
  154.         controlHelpContent.content[ kHMMinimumContentIndex ].u.tagStringRes.hmmResID = 6003;
  155.         controlHelpContent.content[ kHMMinimumContentIndex ].u.tagStringRes.hmmIndex = kEngageButton;
  156.  
  157.         // No maximum content
  158.         controlHelpContent.content[ kHMMaximumContentIndex ].contentType = kHMNoContent;
  159.         
  160.         (void) ::HMSetControlHelpContent( control, &controlHelpContent );
  161.         
  162.         // Set remaining buttons via a 'hdlg' resource
  163.         (void) ::HMSetDialogHelpFromBalloonRsrc( dialog, 6003, kMakeItSoButton + items );
  164.     }
  165. #endif
  166. }
  167.  
  168. ClassicPane::~ClassicPane()
  169. {
  170.     ShortenDITL( fDialog, CountDITL( fDialog ) - fOrigItems );
  171. }
  172.  
  173. void
  174. ClassicPane::ItemHit( SInt16 item )
  175. {
  176.     SInt16            localItem;
  177.     ControlHandle    control;
  178.     SInt16            value;
  179.     Boolean            syncCheck = false;
  180.     SInt16            checkValues = 0;
  181.     
  182.     localItem = item - fOrigItems;
  183.     
  184.     switch ( localItem )
  185.     {
  186.         case kTuneUpCheckBox:
  187.             GetDialogItemAsControl( fDialog, item, &control );
  188.             value = GetControlValue( control );
  189.             
  190.             if ( value == kControlCheckBoxUncheckedValue )
  191.             {
  192.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  193.                 GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  194.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  195.                 GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  196.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  197.             }
  198.             else if ( value == kControlCheckBoxCheckedValue )
  199.             {
  200.                 SetControlValue( control, kControlCheckBoxUncheckedValue );
  201.                 GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  202.                 SetControlValue( control, kControlCheckBoxUncheckedValue );
  203.                 GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  204.                 SetControlValue( control, kControlCheckBoxUncheckedValue );
  205.             }
  206.             else if ( value == kControlCheckBoxMixedValue )
  207.             {
  208.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  209.                 GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  210.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  211.                 GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  212.                 SetControlValue( control, kControlCheckBoxCheckedValue );
  213.             }
  214.             break;
  215.             
  216.         case kConstrictorsCheckBox:
  217.         case kIntermixCheckBox:
  218.             UDialogUtils::ToggleCheckBox( fDialog, item );
  219.             GetDialogItemAsControl( fDialog, fOrigItems + kConstrictorsCheckBox, &control );
  220.  
  221.             if ( GetControlValue( control ) )
  222.                 checkValues |= kConstrictorsMask;
  223.             else
  224.                 checkValues &= ~kConstrictorsMask;
  225.             
  226.             GetDialogItemAsControl( fDialog, fOrigItems + kIntermixCheckBox, &control );
  227.  
  228.             if ( GetControlValue( control ) )
  229.                 checkValues |= kIntermixMask;
  230.             else
  231.                 checkValues &= ~kIntermixMask;
  232.             
  233.             syncCheck = true;
  234.             break;
  235.         
  236.         case kBothButton:
  237.             GetDialogItemAsControl( fDialog, fOrigItems + kDessertRadio, &control );
  238.             SetControlValue( control, kControlCheckBoxMixedValue );
  239.             GetDialogItemAsControl( fDialog, fOrigItems + kFloorWaxRadio, &control );
  240.             SetControlValue( control, kControlCheckBoxMixedValue );
  241.             break;
  242.     }
  243.     
  244.     if ( syncCheck )
  245.     {
  246.         GetDialogItemAsControl( fDialog, fOrigItems + kTuneUpCheckBox, &control );
  247.  
  248.         if ( checkValues == 0 )
  249.             SetControlValue( control, kControlCheckBoxUncheckedValue );
  250.         else if ( checkValues == kAllCheckMask )
  251.             SetControlValue( control, kControlCheckBoxCheckedValue );
  252.         else
  253.             SetControlValue( control, kControlCheckBoxMixedValue );
  254.     }
  255. }
  256.  
  257. pascal void
  258. ClassicPane::DrawPictureProc( ControlHandle control, SInt16 part )
  259. {
  260.     #pragma unused( part )
  261.     
  262.     Rect            bounds;
  263.     RgnHandle        saveClip;
  264.     ClassicPane*    pane;
  265.     
  266.     pane = (ClassicPane*)GetControlReference( control );
  267.     GetControlBounds( control, &bounds );
  268.     
  269.     FrameRect( &bounds );
  270.     InsetRect( &bounds, 1, 1 );
  271.     
  272.     saveClip = NewRgn();
  273.     GetClip( saveClip );
  274.     
  275.     ClipRect( &bounds );
  276.  
  277.     bounds.top -= pane->fPictOffset.v;
  278.     bounds.left -= pane->fPictOffset.h;
  279.     bounds.bottom = bounds.top + pane->fPictHeight;
  280.     bounds.right = bounds.left + pane->fPictWidth;
  281.     
  282.     DrawPicture( pane->fPicture, &bounds );
  283.     
  284.     SetClip( saveClip );
  285.     DisposeRgn( saveClip );
  286. }
  287.  
  288. pascal void
  289. ClassicPane::ScrollingFeedbackProc( ControlHandle control, SInt16 part )
  290. {
  291.     SInt16            startValue, delta, min, max;
  292.     ClassicPane*    pane;
  293.     
  294.     pane = (ClassicPane*)GetControlReference( control );
  295.  
  296.     startValue = GetControlValue( control );
  297.     min = GetControlMinimum( control );
  298.     max = GetControlMaximum( control );
  299.     
  300.     delta = 0;
  301.     
  302.     switch ( part )
  303.     {
  304.         case kControlUpButtonPart:
  305.             if ( startValue > min )
  306.                 delta = MAX( -5, min - startValue );
  307.             break;
  308.         
  309.         case kControlDownButtonPart:
  310.             if ( startValue < max )
  311.                 delta = MIN( 5, max - startValue );
  312.             break;
  313.         
  314.         case kControlPageUpPart:
  315.             if ( startValue > min )
  316.                 if ( control == pane->fHorizontalScrollBar )
  317.                     delta = MAX( -(pane->fUserItemWidth - 1), min - startValue );
  318.                 else
  319.                     delta = MAX( -(pane->fUserItemHeight - 1), min - startValue );
  320.             break;
  321.         
  322.         case kControlPageDownPart:
  323.             if ( startValue < max )
  324.                 if ( control == pane->fHorizontalScrollBar )
  325.                     delta = MIN( pane->fUserItemWidth - 1, max - startValue );
  326.                 else
  327.                     delta = MAX( -(pane->fUserItemHeight - 1), max - startValue );
  328.             break;
  329.     }
  330.  
  331.     if ( delta )
  332.     {
  333.         SetControlValue( control, startValue + delta );
  334.         if ( control == pane->fHorizontalScrollBar )
  335.             pane->fPictOffset.h += delta;
  336.         if ( control == pane->fVerticalScrollBar )
  337.             pane->fPictOffset.v += delta;
  338.         
  339.             // pretty inefficient scrolling here, but you get the point.
  340.             
  341.         DrawOneControl( pane->fUserItem );
  342.     }
  343.     else if ( part == kControlIndicatorPart )
  344.     {
  345.         if ( control == pane->fHorizontalScrollBar )
  346.             pane->fPictOffset.h = startValue - min;
  347.             
  348.         if ( control == pane->fVerticalScrollBar )
  349.             pane->fPictOffset.v = startValue - min;
  350.  
  351.         DrawOneControl( pane->fUserItem );
  352.     }
  353. }
  354.